package com.omi.iberolactalpreventa;

import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.Calendar;
import java.util.GregorianCalendar;
import com.omi.iberolactalpreventa.objects.ItmPedLst;
import com.omi.iberolactalpreventa.objects.ItmProducto;
import android.content.Context;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.TextView;

public class Modulebase {
	
	public static GestionDB db;
	private static Context contxt;
	public static GregorianCalendar calendar;
	public static String ruta="";
	public static String vendedor="";
	public static ItmProducto prodTemp;
	public static String commentTemp;
	public static boolean verNoEnviados;
	public static GestionDescuentos claseDescuento;
	public static String TextDtoLinea="0";
	public static EditText txtNewDimp;
	public static EditText txtNewDto;
	public static String idClient;
	public static EditText txtNewPudkg;
	public static ItmPedLst selectedLine;
	public static boolean isFtp;
	public static String ultimoArchivoSended;
	public static EditText txtNewImporte;
	
	public static void init(Context context)
	{
		db = new GestionDB(context, "omi-db", null, 1);
		calendar = new GregorianCalendar();
		contxt =context;
		claseDescuento = new GestionDescuentos();
		}

	public static ArrayAdapter<String> inicializarFecha()
	{
//		Completamos el campo de texto con la fecha de hoy:
		String dia;
		String mes;
		
		switch(calendar.get(Calendar.DAY_OF_WEEK))
		{
		case Calendar.SUNDAY:
			dia = "Domingo";
			break;
		case Calendar.MONDAY:
			dia = "Lunes";
			break;
		case Calendar.TUESDAY:
			dia = "Martes";
			break;
		case Calendar.WEDNESDAY:
			dia = "Miercoles";
			break;
		case Calendar.THURSDAY:
			dia = "Jueves";
			break;
		case Calendar.FRIDAY:
			dia = "Viernes";
			break;
		case Calendar.SATURDAY:
			dia = "Sabado";
			break;
			default:
				dia ="";
		}
		
		switch(calendar.get(Calendar.MONTH))
		{
		case Calendar.JANUARY:
			mes = "Enero";
			break;
		case Calendar.FEBRUARY:
			mes = "Febrero";
			break;
		case Calendar.MARCH:
			mes = "Marzo";
			break;
		case Calendar.APRIL:
			mes = "Abril";
			break;
		case Calendar.MAY:
			mes = "Mayo";
			break;
		case Calendar.JUNE:
			mes = "Junio";
			break;
		case Calendar.JULY:
			mes = "Julio";
			break;
		case Calendar.AUGUST:
			mes = "Agosto";
			break;
		case Calendar.SEPTEMBER:
			mes = "Septiembre";
			break;
		case Calendar.OCTOBER:
			mes = "Octubre";
			break;
		case Calendar.NOVEMBER:
			mes = "Noviembre";
			break;
		case Calendar.DECEMBER:
			mes = "Diciembre";
			break;
		default:
			mes="";
			break;
		}
		String fecha =dia +" "+ calendar.get(Calendar.DAY_OF_MONTH)+" de "+mes+" de "+calendar.get(Calendar.YEAR);
		
		String[] itmsFecha = new String[]{fecha};
	
		ArrayAdapter<String> adaptFecha = new ArrayAdapter<String>(contxt, android.R.layout.simple_list_item_1, itmsFecha);
		return adaptFecha;
	}
	
	  public static String Redondear(String Numero ,int NumDec)
	  {  
	    float dValor2;

	    if(Float.parseFloat(Numero) < 0)
	    {
	        dValor2 = (float) (-Float.parseFloat(Numero) *  Math.pow(10 , NumDec));
	        dValor2 =  -Math.round((dValor2+0.499));
	    }
	    else
	    {
	     dValor2 = (float) (Float.parseFloat(Numero) * Math.pow(10 , NumDec));
	     dValor2 = Math.round((dValor2+0.499));
	        }
        String formatString = "%."+ NumDec + "f";
        String toReturn = String.format(formatString, dValor2 / Math.pow(10 , NumDec));
        return toReturn;

	    }
}
